package com.learn.game_challenger.service;

import com.learn.game_challenger.entity.role;

public class behavior {
    //攻击者攻击
    private role attacker;
    private role defender;
    public behavior(role attacker, role defender) {
        this.attacker = attacker;
        this.defender = defender;
    }
    public void hit(role attacker, role defender) {
        if(attacker.getAttack() <= defender.getDefense()) {
            System.out.println(attacker.getName() + "攻击失败");
        }
        else {
        defender.sethealth(defender.getHealth() - attacker.getAttack() + defender.getDefense());
        System.out.println(attacker.getName() + "攻击了" + defender.getName() + "，" + defender.getName() + "剩余血量：" + defender.getHealth());
        }
    }

    public boolean isKill(role defender) {
        return defender.getHealth() <= 0;
    }

    public boolean canPass(role challenger, role boss) {
        if(challenger.getAttack() <= boss.getDefense()) {
            System.out.println("你太弱了，甚至伤害不到boss一分一毫");
            return false;
        }
        else {
            return true;
        }
    }

    public void upgrade(role challenger, int index) {
        switch (index) {
            case 1:
            challenger.sethealth(challenger.getHealth() + 20);
            break;
            case 2:
            challenger.setAttack(challenger.getAttack() + 5);
            break;
            case 3:
            challenger.setDefense(challenger.getDefense() + 5);
            break;
        }
    }
}